package main.cn.dao.impl;

import main.cn.dao.CarDao;
import main.cn.pojo.Car;

import java.util.List;


public class CarDaoImpl extends BaseDao implements CarDao {
    @Override
    public int addCar(Car car) {
        String sql = "insert into cars (id,name,description) values(?,?,?)";
        return update(sql,car.getId(),car.getName(),car.getDescription());
    }

    @Override
    public int deleteCar(int id) {
        String sql = "delete from cars where id = ?";
        return update(sql,id);
    }

    @Override
    public int updateCar(Car car) {
        String sql = "update cars set name = ?,description = ? where id = ?";
        return update(sql,car.getName(),car.getDescription(),car.getId());
    }

    @Override
    public Car queryCarById(int id) {
        String sql = "select id,name,description from cars where id = ?";
        return queryForOne(Car.class,sql,id);
    }

    @Override
    public List<Car> queryCars() {
        String sql = "select id,name,description from cars";
        return queryForList(Car.class,sql);
    }
}
